<template>
	<view>
		<view class="" style="padding-bottom: 150rpx;">
			<view class="mainpadding_top ffffff dingwei flexbetween fdlb" v-for="(item,index) in shop" :key="item.id" @click="checkitem(item)">
				<view class="checkfocus" v-if="item.ischeck">
					<u-icon name="checkbox-mark" color="#fff" size="16"></u-icon>
				</view>
				<view class="flexleft">
					<image :src="item.logoimage" class="listleftimg2 margin_right" mode="">
					</image>
					<view class="">
						<view class="hei_text main_size bold xiankuan">{{item.name}}</view>
						<view class="xiaohui margin_top">綁定時間：{{item.bangdingtime}}</view>
					</view>
				</view>
				<template v-if="get_type">
					<u-number-box :min="0" button-size="36" color="#000000" bgColor="#F7F7F7" iconStyle="color: #fff"
						v-model="item.buynumber"></u-number-box>
				</template>
			</view>
		</view>
		<view class="posibottom mainpadding">
			<view class="submitbtn" @click="submit">確認</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				shop: [],
				type: 1,
				listids: [],
				get_type:false//是否隨機領取
			}
		},
		onLoad(options) {
			let data = JSON.parse(decodeURIComponent(options.msg));
			this.type = data.type
			this.listids = data.rallshop
			console.log(this.listids);
			this.get_type = data.get_type//是否隨機領取
			this.get()
		},
		watch:{
			shop:{
				deep:true,
				handler(newval){
					if(this.get_type){
						this.shop.forEach(item=>{
							if(item.buynumber==0){
								item.ischeck = false
							}else{
								item.ischeck = true
							}
						})
					}
				}
			}
		},
		methods: {
			checkitem(item){
				if(!this.get_type){
					item.ischeck = item.ischeck?false:true
				}
			},
			async get() {
				let res = await this.http.request("/api/shop/fendianlist", "POST", {})
				if (res.code == 1) {
					res.data.forEach(item => {
						this.$set(item, "ischeck", false)
						this.$set(item, "buynumber", 0)
						this.$set(item, "editid", "")
						this.listids.forEach(current => {
							if (current.shop_id == item.id) {
								item.ischeck = true
								item.buynumber = current.num || 0
								item.editid = current.id
							}
						})
						item.logoimage = this.imgUrl + item.logoimage
					})
					this.shop = res.data
				} else if (res.code == 0) {
					this.http.toast(res.msg);
				} else {
					this.http.toast('暫無分店');
				}
			},
			submit() {
				let arr = []
				this.shop.forEach(item => {
					if (item.ischeck) {
						arr.push({
							id:item.editid,
							shop_id:item.id,
							num:item.buynumber
						})
					}
				})
				uni.$emit("checkfd", arr)
				uni.navigateBack(1)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.fdlb ::v-deep .u-number-box__minus {
		background-color: #EC7AA0 !important;
	}

	.fdlb ::v-deep .u-number-box__plus {
		background-color: #EC7AA0 !important;
	}

	.fdlb ::v-deep .uicon-minus {
		color: #fff !important;
	}

	.fdlb ::v-deep .uicon-plus {
		color: #fff !important;
	}
</style>